﻿
(function (window, jQuery, undefined) {
    "use strict";
    var $ = jQuery;

    if (window.lanHomepage === undefined) {
        window.lanHomepage = {};
    }
    if (window.lanHomepage.sharedLayout === undefined) {
        window.lanHomepage.sharedLayout = {};
    }

    var publics = {
        deleteSponsorLogo: function (id) {

            $.msg({
                bgPath: "/Images/",
                content: '<p>Delete this logo?</p>' +
                         '<p class="btn-wrap">' +
                            '<span id="yes">Yes</span>' +
                            '<br/>' +
                            '<span id="no">no</span>' +
                         '</p>',
                autoUnblock: false,
                clickUnblock: false,
                afterBlock: function () {
                    $("#yes").bind("click", function () {
                        $.ajax({
                            url: "/Base/DeleteSponsorLogo",
                            type: "POST",
                            data: JSON.stringify({ _id: id}),
                            contentType: "application/json; charset=utf-8",
                            success: function (data, result) {
                                if (data == "True") {
                                    $("#" + id).remove();
                                    $.msg("replace", 'Logo deleted.');
                                    $.msg("unblock", "2000");
                                }
                                else {
                                    console.log("data: " + data + ", result: " + result);

                                    $.msg("replace", 'Error detected - id not found / check console');
                                    $.msg("unblock", "2000");
                                }
                            },
                            error: function (data, result) {
                                console.log("data: " + data + ", result: " + result);

                                $.msg("replace", 'Error detected - connection shizzle perhaps / check console');
                                $.msg("unblock", "2000");
                            }
                        });

                    });
                    $("#no").bind("click", function () {
                        $.msg("unblock", "0");
                    });
                }
            });
        }
    }
    $.extend(window.lanHomepage.sharedLayout, publics);
})(window, jQuery);
